package jvm;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * 测试OOM(OutOfMemoryError)
 *
 * @author jack.wu
 * @version 1.0
 * @date 2020-05-16
 */
public class OOMTest {

    public static void main(String[] args) throws InterruptedException {
        List<Picture> pictures = new ArrayList<>(10);

        while (true) {
            TimeUnit.MILLISECONDS.sleep(200);
            pictures.add(new Picture(new Random().nextInt(1024 * 1024)));
        }
    }
}

/**
 * 模拟照片
 */
class Picture {

    int[] data;

    public Picture(int len) {
        this.data = new int[len];
    }
}
